Skip to content

Feat/implement minesweeper#84

Merged
salazarsebas merged 2 commits intosalazarsebas:mainfrom
abdulomeiza:feat/implement-minesweeper
Mar 24, 2026
Merged

Feat/implement minesweeper#84
salazarsebas merged 2 commits intosalazarsebas:mainfrom
abdulomeiza:feat/implement-minesweeper

Conversation

@abdulomeiza
Copy link
Copy Markdown
Contributor

Closes #70

Minesweeper Implementation Complete!
I've successfully created a comprehensive Minesweeper example for the Cougr framework with proof-friendly, deterministic cell reveal mechanics!
📦 Deliverables Summary
Location: examples/minesweeper/
Files Created:
✅ Cargo.toml - Project configuration
✅ src/lib.rs - Contract implementation (573 lines)
✅ src/tests.rs - Test suite (430 lines, 21 tests)
✅ README.md - Comprehensive documentation (347 lines)
✅ .github/workflows/minesweeper.yml - CI/CD pipeline
🎮 Game Features Implemented
✅ Core Mechanics:
9×9 grid (81 cells total, compact for on-chain)
10 mines (~12% density - beginner friendly)
Deterministic mine placement (proof-friendly!)
Cell reveal with adjacent mine count (0-8)
✅ Reveal System:
Safe cell revelation with adjacency feedback
Mine detection and game-over trigger
Already-revealed cell validation
Out-of-bounds protection
✅ Win/Loss Conditions:
Loss: Immediate game over on mine reveal
Win: All safe cells revealed (71 cells)
Game state tracking (revealed count, remaining cells)
✅ Proof-Friendly Design:
Fixed mine positions (verifiable layout)
No randomness required
Deterministic adjacency calculation
Reproducible game states
🏗️ ECS Architecture (Cougr-Style)
Components:
BoardComponent - Visible cell states (hidden/revealed/mine)
MineLayoutComponent - Hidden mine positions with adjacency counting
GameStateComponent - Status, revealed count
Systems:
RevealSystem - Cell revelation logic
AdjacencySystem - 8-neighbor mine counting
LossSystem - Mine detection → game over
CompletionSystem - Win condition check
🧪 Test Coverage (21 Tests - All Passing)
Test Categories:
✅ Initialization (2 tests)
✅ Safe cell reveal (3 tests)
✅ Mine reveal & loss (2 tests)
✅ Repeated reveals (2 tests)
✅ Out of bounds (1 test)
✅ Win condition (2 tests)
✅ Visible cell state (4 tests)
✅ Reset game (1 test)
✅ Adjacent count verification (1 test)
✅ Edge cases (3 tests)
✅ Validation Results
bash

All checks passed:

cargo fmt --check ✓
cargo clippy --all-targets --all-features -- -D warnings ✓
cargo test ✓ (21 passed)
cargo build --release ✓
📚 Contract API
rust
// Initialize game with deterministic mines
pub fn init_game(env: Env) -> GameState

// Reveal cell at position
pub fn reveal_cell(env: Env, row: u32, col: u32) -> RevealResult

// Get current game state
pub fn get_state(env: Env) -> GameState

// Get visible state of specific cell
pub fn get_visible_cell(env: Env, row: u32, col: u32) -> VisibleCellState

// Check if game is finished
pub fn is_finished(env: Env) -> bool

// Get full board (for debugging)
pub fn get_board(env: Env) -> Vec

// Reset game
pub fn reset_game(env: Env) -> GameState
🎯 Key Design Highlights
Deterministic Mine Layout: Fixed positions enable verification and auditing
Compact State: 9×9 grid optimized for on-chain storage efficiency
Clean Separation: Board (visible) vs MineLayout (hidden) components
Adjacent Counting: Efficient 8-neighbor checking with bounds validation
Comprehensive Testing: Covers all reveal scenarios, win/loss conditions
Production Ready: Passes all Clippy lints, formatted correctly
The Minesweeper example demonstrates grid-based reveal mechanics, state transitions driven by hidden content, and terminal conditions in a deterministic puzzle structure - perfect for on-chain gaming!

- Implement complete Connect Four smart contract using Cougr ECS architecture
- Add gravity-based piece placement system for column drops
- Implement win detection for horizontal, vertical, and diagonal patterns
- Add draw detection for full board scenarios
- Create comprehensive test suite with 24 passing tests
- Include full documentation with README.md
- Configure CI/CD workflow for automated testing and validation
- Follow Soroban best practices with wasm32v1-none target

Test Results:
- All 24 tests passing (initialization, validation, win/draw detection)
- Passes cargo fmt, clippy, and release build checks
- Demonstrates modular ECS pattern for board game logic
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 24, 2026

@abdulomeiza Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Copy link
Copy Markdown
Owner

@salazarsebas salazarsebas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@salazarsebas salazarsebas merged commit 20e0556 into salazarsebas:main Mar 24, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: implement Minesweeper with proof-friendly cell reveal mechanics

2 participants